import 'package:flutter/material.dart';
import 'package:wan_android_flutter/common_code/configs/app_color_config.dart';
import 'package:wan_android_flutter/common_code/configs/app_config.dart';
import 'package:wan_android_flutter/module_code/short_video/models/short_video_list_model.dart';

class ShortVideoPageCell extends StatelessWidget {
  const ShortVideoPageCell({super.key, required this.item});

  final ShortVideoListItemModel item;

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // 标题
          _buildTopTitle(),
          // 图片
          _buildMidImg(),
          // 底部内容
          _buildBotContent(),
          // 分割线
          Divider(
            thickness: 0.5,
            color: AppColorConfig.backgroundColor,
            indent: 10,
            endIndent: 10,
          ),
        ],
      ),
    );
  }

  Row _buildBotContent() {
    return Row(
      children: [
        Padding(
          padding: EdgeInsetsGeometry.all(10),
          child: ClipOval(
            child: FadeInImage.assetNetwork(
              placeholder: AppConfig.imgPath + "empty.png",
              image: item.author_avatar ?? '',
              width: 30,
              height: 30,
            ),
          ),
        ),
        Text(item.source_name ?? '', style: TextStyle(fontSize: 13)),
        Expanded(
          flex: 1,
          child: Padding(
            padding: EdgeInsetsGeometry.symmetric(horizontal: 10),
            child: Text(
              item.publish_time ?? '',
              style: TextStyle(fontSize: 13),
            ),
          ),
        ),
        TextButton.icon(
          onPressed: () {},
          iconAlignment: IconAlignment.start,
          label: Text(item.like.toString(), style: TextStyle(fontSize: 13)),
          icon: Icon(Icons.favorite_border_outlined),
        ),
      ],
    );
  }

  Padding _buildMidImg() {
    return Padding(
      padding: EdgeInsetsGeometry.symmetric(horizontal: 10),
      child: Stack(
        alignment: AlignmentDirectional.center,
        children: [
          AspectRatio(
            aspectRatio: 16 / 9,
            child: ClipRRect(
              borderRadius: BorderRadius.all(Radius.circular(10)),
              child: FadeInImage.assetNetwork(
                placeholder: AppConfig.imgPath + "empty.png",
                image: item.poster_big ?? '',
                fit: BoxFit.cover,
              ),
            ),
          ),
          Icon(Icons.play_circle_outline, size: 50, color: Colors.white),
          Positioned(
            left: 0,
            right: 0,
            bottom: 0,
            child: Container(
              alignment: Alignment.centerRight,
              decoration: BoxDecoration(
                color: Color.fromARGB(100, 0, 0, 0),
                borderRadius: BorderRadius.only(
                  bottomLeft: Radius.circular(10),
                  bottomRight: Radius.circular(10),
                ),
              ),
              height: 30,
              child: Padding(
                padding: EdgeInsetsGeometry.only(right: 5),
                child: Text(
                  item.duration ?? '',
                  style: TextStyle(fontSize: 14, color: Colors.white),
                  textAlign: TextAlign.center,
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Padding _buildTopTitle() {
    return Padding(
      padding: EdgeInsetsGeometry.all(10),
      child: Text(
        item.title ?? '',
        style: TextStyle(
          fontSize: 15,
          fontWeight: FontWeight.w600,
          color: Colors.black,
        ),
      ),
    );
  }
}
